#include "Common.h"
#include "Engine.h"
using namespace nelsk;

Engine::Engine() :
	_window(sf::VideoMode(1200,1024,32),"SFML_Sandbox")
{
}


Engine::~Engine()
{
}

bool Engine::Init()
{
	return true;
}

void Engine::Draw()
{
	_window.clear();
	_window.draw(_mySprite);
	_window.display();
}

void Engine::ProcessInput()
{
	sf::Event evt;
	// Loop through all window events
	while(_window.pollEvent(evt))
	{
		if(evt.type == sf::Event::Closed)
			_window.close();
	}
}

void Engine::Update()
{

}

void Engine::Mainloop()
{
	_tileSheetManager.LoadTexture("DemoSheet","DemoSheet.png");
	_mySprite.setTexture(*(_tileSheetManager.find("DemoSheet")->second));
	// Loop until our window is closed
	while(_window.isOpen())
	{
		ProcessInput();
		Update();
		Draw();
	}
}

void Engine::StartGame()
{
	if(!Init())
	{
		throw "Could not initialize engine";
	}
	Mainloop();
}

TileSheetManager& Engine::GetTileSheetManager()
{
	return _tileSheetManager;
}

GameObjectManager& Engine::GetGameObjectManager()
{
	return _gameObjectManager;
}

PhysicsManager& Engine::GetPhysicsManager()
{
	return _physicsManager;
}

InputManager& Engine::GetInputManager()
{
	return _inputManager;
}

sf::RenderWindow& Engine::GetRenderWindow()
{
	return _window;
}
